﻿<?php
if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: dbcl-dangnhap.php");
	}
	include "connect.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<table width="700" align="center">
	

	<tr>
		<td>
		<!--chứa bảng tìm kiếm lop hoc phan -->
			<table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
						
					  <tr> 
							<td height="30" colspan="3" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
								<span class="style2" style="font-size:20px">Chọn Lớp Học Phần Cập nhật</span></td>
					  </tr>
						
						<tr bordercolor="#FFFFFF"> 
						  <td colspan="3" height="50" align="center" style="font-size:18px">
						  
								  <form name="f" method="post">
										    <br />
											Mã Học Phần :    &nbsp;&nbsp;			
											<input name="mahp" size="8" type="text" /> &nbsp;&nbsp;<br /><br />
											Nhóm :    &nbsp;&nbsp;			
											<input name="nhom" size="8" type="text" /> &nbsp;&nbsp;<br /><br />
											
											  
										   <input name="tk" type="submit"  id="tk" value="   Tìm Kiếm  " /><br /><br />
								  </form>
						 </td>
					  </tr>
					  
					
			</table>
		</td>
	</tr>
</table>

<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>

<?php
 if(isset($_POST["tk"]))
{
     $mahp=$_POST["mahp"];
	 $stt=$_POST["nhom"];
	 $sql=mysql_query("select max(ma_hknk) from `hocki nienkhoa`");
	 $s=mysql_fetch_row($sql);
	 $hknk=$s[0];
	 $sql_query=mysql_query("select * from `lop hoc phan` where ma_hp = '$mahp' and stt_nhom='$stt' and ma_hknk='$hknk' ");
	 $count=mysql_num_rows($sql_query);
	 if($count > 0)
	 {
			        $t=mysql_fetch_row($sql_query);
					$ss=$t[3];
					$magv=$t[4];
					
				
				?>
									 <form name="f" method="post" action="" onsubmit="">
							  <table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
									
								  <tr> 
										<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Thông tin Lớp Học Phần</span></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Mã Học Phần:</td>
									  <td align="left"><input type="text" name="mahp" value="<?php echo $mahp; ?>"  class="mau" readonly="" size="8" /></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Nhóm:</td>
									  <td align="left"><input type="text" name="nhom" value="<?php echo $stt; ?>"  class="mau" readonly="" size="8" /></td>
								  </tr>
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Sĩ Số:</td>
									  <td align="left"><input type="text" name="ss" value="<?php echo $ss; ?>"    size="6" /></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Giảng Viên:</td>
									  <td align="left"><input type="text" name="magv" value="<?php echo $magv; ?>"    size="6" /></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="right" height="30"><input type="submit" value="Cập nhật" name="cn" /></td>
									  <td align="left">
									                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														 <input type="submit" value="Xóa" name="xoa" size="8" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									                    <input type="reset" value="Làm Lại" name="huy" /></td>
								 </tr>
								 <tr><td colspan="2" height="20">&nbsp;</td></tr>
								
						</table>
				  </form>	
				  
				<?php 
}//ngoac if count
else  echo "<div align='center' style='font-size:24px; font-weight:bold; color:#FF0000'>Không tồn tại Lớp Học Phần này!</div>";
}//ngoac isset 
				?>  
				
<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>	
<?php 
                if(isset($_POST["cn"]))
				{
				          $mahp=$_POST["mahp"];
				          $stt=$_POST["nhom"];
						  $ss=$_POST["ss"];
						  $magv=$_POST["magv"];
						  $sql=mysql_query("select max(ma_hknk) from `hocki nienkhoa`");
						  $s=mysql_fetch_row($sql);
						  $hknk=$s[0];
						  $kq=mysql_query(" update `lop hoc phan` set sisolop_hp='$ss',ma_gv='$magv' where ma_hknk='$hknk' and stt_nhom='$stt' and ma_hp='$mahp' ");
						  echo"<script type='text/javascript'>alert('Cap Nhat Thanh Cong')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=dbcl-capnhat.php?nav=capnhat">';
						  
				}
				if(isset($_POST["xoa"]))
				{
				          $mahp=$_POST["mahp"];
				          $stt=$_POST["nhom"];
						  $sql=mysql_query("select max(ma_hknk) from `hocki nienkhoa`");
						  $s=mysql_fetch_row($sql);
						  $hknk=$s[0];
						  $str=mysql_query("select * from `danh gia` where ma_hknk='$hknk' and stt_nhom='$stt' and ma_hp='$mahp' ");
						  $str1=mysql_num_rows($str);
						  if($str1>0)
						  {
						  echo"<script type='text/javascript'>alert('Da ton tai sinh vien danh gia! Ban khong duoc Xoa!')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=dbcl-capnhat.php?nav=capnhat">';
						  }
						  else
						  {
						  $kq=mysql_query(" delete from `lop hoc phan` where ma_hknk='$hknk' and stt_nhom='$stt' and ma_hp='$mahp' ");
						  echo"<script type='text/javascript'>alert('Xoa Thanh Cong')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=dbcl-capnhat.php?nav=capnhat">';
						  }
						  
				}
?>

</body>
</html>
